<?php
	class Template {	
		static protected $tpl;
		
		public function __construct() {
			self::getInstance();
			
			self::$tpl->caching = TPL_CACHE_OPEN;
			self::$tpl->cache_lifetime = TPL_CACHE_TIME;
			self::$tpl->template_dir = TPL_PATH;//TPL_PATH;
			self::$tpl->compile_dir = VIEW_PATH;//VIEW_PATH;
			self::$tpl->cache_dir = CACHE_PATH;
			self::$tpl->right_delimiter = TPL_RIGHT_DELIMITER;
			self::$tpl->left_delimiter = TPL_LEFT_DELIMITER;
		}
		
		static function getInstance() {
			if( is_null(self::$tpl) ) {
				self::$tpl = TplDriver::factory(TplDriver::TYPE_SMARTY);
				if(self::$tpl == null) {
					_error("template getinstance failed", 'fatal');
				}
			}
			return self::$tpl;
		}
		
		public function display($template, & $view) {
			foreach ($view as $key=>$value) {
				self::$tpl->assign($key, $value);
			}
			self::$tpl->display($template);
		}
		
		public function assgin($key, & $value) {
			self::$tpl->assign($key, $value);
		}
	}